// 评论小模块

<template>
  <div class="commentItem">
    <!-- 使用递归：再次渲染可能存储的上一级评论 -->
    <mycommentItem
      v-if="parent.parent"
      :parent="parent.parent"
      @replyComment="sendComment"
    ></mycommentItem>
    <div class="top">
      <div class="left">
        <p>{{parent.user.nickname}}</p>
        <i>2分钟前</i>
      </div>

      <span @click="sendComment(parent)">回复</span>
    </div>
    <div class="bottom">{{parent.content}}</div>
  </div>
</template>

<script>
export default {
  // 如果为组件设置了name属性，那么这个name属性就相当于注册了当前组件，你可以直接使用
  name: "mycommentItem",
  props: ["parent"],
  methods: {
    sendComment(comment) {
      console.log(comment);
      this.$emit("replyComment",comment);
    },
  },
};
</script>

<style lang="less" scoped>
.commentItem {
  margin-top: 5 * 100vw/360;
  border: 1 * 100vw/360 solid #ccc;
  padding: 3 * 100vw/360;
  .top {
    font-size: 12 * 100vw/360;
    color: #aaa;
    display: flex;
    justify-content: space-between;
  }
  .bottom {
    font-size: 13 * 100vw/360;
    line-height: 40 * 100vw/360;
  }
}
</style>